package com.example.demo.his.leetcode;

/**
 * @auther zzc
 * @date 2021/4/6 14:10
 */
public class 不同路径 {

    /**
     * 动态规划
     * 列转移态方程  找边界
     * f(i,j) = f(i-1,j)+f(i,j-1)
     */
    public int pathNums(int m, int n) {
        int[][] f = new int[m][n];
        //边界
        for (int i = 0; i < m; ++i) {
            f[i][0] = 1;
        }
        for (int i = 0; i < n; ++i) {
            f[0][i] = 1;
        }
        for (int i = 1; i < m; ++i) {
            for (int j = 1; j < n; ++j) {
                f[i][j] = f[i - 1][j] + f[i][j - 1];
            }
        }
        return f[m - 1][n - 1];
    }
}
